deploy host | | Cell 1 | Search

The deployAws function packages project files into a zip archive and deploys them to the AWS Lambda function eloqua_test in the us-west-2 region.

Run example

npm run import -- "deploy aws"

deploy aws

function deployAws() {
    return execCmd(os.platform() === 'win32' ? `
powershell.exe -nologo -noprofile -command "& { \
    Add-Type -A 'System.IO.Compression.FileSystem'; \
    Remove-Item –path index.zip –recurse -erroraction 'silentlycontinue'; \
    $files = @('index.js', 'eloqua-service.js', 'eloqua-create.js', 'eloqua-mapper.js', 'https-request-polyfill.js', 'sync-zuora-eloqua.js', 'zuora-service.js', 'zuora-renewals-query.js', 'package.json', 'package-lock.json'); \
    $files | Compress-Archive -DestinationPath index.zip; \
    & aws lambda update-function-code --region us-west-2 --function-name eloqua_test --zip-file fileb://index.zip; \
}"` : `
rm index.zip 
zip ./index.zip -r index.js eloqua-service.js eloqua-create.js eloqua-mapper.js https-request-polyfill.js sync-zuora-eloqua.js zuora-service.js zuora-renewals-query.js package.json package-lock.json
aws lambda update-function-code --region us-west-2 --function-name eloqua_test --zip-file fileb://index.zip
`, {cwd: PROJECT_PATH});
}

What the code could have been:

/**
 * Deploys an AWS Lambda function using the provided script.
 *
 * @returns {Promise} The output of the deployed function.
 */
async function deployAws() {
  const { platform } = process;

  const command = platform === 'win32'
   ? `
      # PowerShell script to deploy an AWS Lambda function
      Add-Type -A 'System.IO.Compression.FileSystem'
      Remove-Item –path index.zip –recurse -erroraction'silentlycontinue'
      $files = @(
        'index.js',
        'eloqua-service.js',
        'eloqua-create.js',
        'eloqua-mapper.js',
        'https-request-polyfill.js',
       'sync-zuora-eloqua.js',
        'zuora-service.js',
        'zuora-renewals-query.js',
        'package.json',
        'package-lock.json'
      )
      $files | Compress-Archive -DestinationPath index.zip
      aws lambda update-function-code --region us-west-2 --function-name eloqua_test --zip-file fileb://index.zip
    `
    : `
      # Bash script to deploy an AWS Lambda function
      rm index.zip
      zip./index.zip -r index.js eloqua-service.js eloqua-create.js eloqua-mapper.js https-request-polyfill.js sync-zuora-eloqua.js zuora-service.js zuora-renewals-query.js package.json package-lock.json
      aws lambda update-function-code --region us-west-2 --function-name eloqua_test --zip-file fileb://index.zip
    `;

  try {
    const { stdout, stderr } = await execCmd(command, { cwd: PROJECT_PATH });
    return stdout.trim();
  } catch (error) {
    console.error(`Error deploying AWS Lambda function: ${stderr.trim()}`);
    return Promise.reject(error);
  }
}

This code defines a function deployAws that deploys a Lambda function named eloqua_test to the AWS us-west-2 region.

Here's a breakdown:

  1. Platform Check:

  2. File Preparation:

  3. AWS Lambda Deployment:

  4. Environment Variables:

  5. Error Handling:

Let me know if you have any more questions!